



/**
 * revenue管理初始化
 */
var Revenue = {
    id: "RevenueTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Revenue.initColumn = function () {
    return [
            {field: 'selectItem', radio: true},
            {title: '编号', field: 'id', visible: false, align: 'center', valign: 'middle',switchable:false},
			{title: '平台编号', field: 'platform', visible: false, align: 'center', valign: 'middle'},
			{title: '平台名称', field: 'platformName', visible: true, halign:'center', align: 'right', valign: 'middle'},
            {title: '彩票盈亏', field: 'lotterProfit', visible: true, halign:'center', align: 'right', valign: 'middle'},
            {title: 'KG盈亏', field: 'kgProfit', visible: true, halign:'center', align: 'right', valign: 'middle'},
            {title: 'AG盈亏', field: 'agProfit', visible: true, halign:'center', align: 'right', valign: 'middle'},
            {title: 'BBIN盈亏', field: 'bbinProfit', visible: true, halign:'center', align: 'right', valign: 'middle'},
            {title: 'PT盈亏', field: 'ptProfit', visible: true, halign:'center', align: 'right', valign: 'middle'},
            {title: 'MG盈亏', field: 'mgProfit', visible: true, halign:'center', align: 'right', valign: 'middle'},
            {title: 'DS盈亏', field: 'dsProfit', visible: true, halign:'center', align: 'right', valign: 'middle'},
            {title: 'VR盈亏', field: 'vrProfit', visible: true, halign:'center', align: 'right', valign: 'middle'},
            {title: 'SB盈亏', field: 'sbProfit', visible: true, halign:'center', align: 'right', valign: 'middle'},
            {title: 'GP盈亏', field: 'gpProfit', visible: true, halign:'center', align: 'right', valign: 'middle'},
            {title: '反点金额', field: 'rebateProfit', visible: true, halign:'center', align: 'right', valign: 'middle'},
			{title: '活动赠送', field: 'hdzsProfit', visible: true, halign:'center', align: 'right' , valign: 'middle'},
            {title: '报表日期', field: 'revtime', visible: true, align: 'center', valign: 'middle',width:'150px',
			formatter:function(value,row,index){
                        return value.substring(0,10);
				}
			},
            {title: '更新日期', field: 'updatetime', visible: true, align: 'center', valign: 'middle',width:'150px'}
			
    ];
};

/**
 * 检查是否选中
 */
Revenue.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        Revenue.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加revenue
 */
Revenue.openAddRevenue = function () {
    var index = layer.open({
        type: 2,
        title: '添加',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/revenue/revenue_add'
    });
    this.layerIndex = index;
};

/**
 * 批量上传
 */
Revenue.openAddRevenueList = function () {
    var index = layer.open({
        type: 2,
        title: '批量添加盈亏报表',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/revenue/revenue_add_list'
    });
    this.layerIndex = index;
};


/**
 * 导出 
 */
Revenue.exportRevenue = function () { 
			var beginDate = $("#beginDate").val();
	        var endDate   = $("#endDate").val();
			if(beginDate=='' || beginDate==undefined || endDate=='' || endDate==undefined   ){
				layer.open({
				  content: '请选择开始时间和结算时间导出!'
				});
				return;
			}
	    window.location="/revenue/load?beginDate="+beginDate+"&endDate="+endDate;
    
};



/**
 * 打开查看revenue详情
 */
Revenue.openRevenueDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: 'revenue详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/revenue/revenue_update/' + Revenue.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除revenue
 */
Revenue.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/revenue/delete", function (data) {
            Feng.success("删除成功!");
            Revenue.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("revenueId",this.seItem.id);
        ajax.start();
    }
};

Revenue.resetSearch = function () {
    $("#platform").val("");
    $("#beginDate").val("");
    $("#endDate").val("");
}

/**
 * 查询表单提交参数对象
 * @returns {{}}
 */
Revenue.formParams = function() {
    var queryData = {};
    queryData['beginDate'] = $("#beginDate").val();
	queryData['endDate'] = $("#endDate").val();
	queryData['platform'] = $("#platform").val();
    return queryData;
}

/**
 * 查询revenue列表
 */
Revenue.search = function () {
    Revenue.table.refresh({query: Revenue.formParams()});
    $("#RevenueSum").remove();
    $("#RevenueTable").after(  Revenue.tatol()   )
};

Revenue.tatol= function(){
	
	var tatol;
    var ajax = new $ax(Feng.ctxPath + "/revenue/tatol", function (result) {
        tatol=result;
    }, function (result) {
        Feng.error("查询失败!" + result.responseJSON.message + "!");
    });
    ajax.setData(Revenue.formParams());
    ajax.start();

  /*  var rowTem = '<div id="RevenueSum" class="alert  alert-dismissable" style="font-size: medium;color: #1f1d1e;background-color: #e4d6cc;border-color: #8392d7;">'
	+"总计: AG盈亏:"+tatol.agProfit+" ,BBIN盈亏:"+tatol.bbinProfit+" ,PT盈亏:"+tatol.ptProfit+" ,MG盈亏:"+tatol.mgProfit
	+" ,DS盈亏:"+tatol.dsProfit+" ,VR盈亏:"+tatol.vrProfit+" ,SB盈亏:"+tatol.sbProfit+" ,GP盈亏:"+tatol.gpProfit+" ,彩票盈亏:"+tatol.lotterProfit
	+" ,KG盈亏:"+tatol.kgProfit+" ,活动赠送:"+tatol.hdzsProfit+" ,返点:"+tatol.rebateProfit
	+'</div>';*/

    var rowTem = '<div><table id="RevenueSum" data-mobile-responsive="true" data-click-to-select="false" class="table table-hover table-striped" style="margin-top: -0px;color: #2A2E36;font-size: 14px;"><tbody id="RevenueSum" >'+
        '<tr data-index="0">'+
        '<td style="text-align: center; vertical-align: middle;  width: 132px; ">总计：</td> '+
        '<td style="text-align: right; vertical-align: middle; ">'+tatol.lotterProfit+'</td>'+
        '<td style="text-align: right; vertical-align: middle; ">'+tatol.kgProfit+'</td> '+
        '<td style="text-align: right; vertical-align: middle; ">'+tatol.agProfit+'</td>'+
        '<td style="text-align: right; vertical-align: middle; ">'+tatol.bbinProfit+'</td>'+
        '<td style="text-align: right; vertical-align: middle; ">'+tatol.ptProfit+'</td>'+
        '<td style="text-align: right; vertical-align: middle; ">'+tatol.mgProfit+'</td>'+
        '<td style="text-align: right; vertical-align: middle; ">'+tatol.dsProfit+'</td>'+
        '<td style="text-align: right; vertical-align: middle;">'+tatol.vrProfit+'</td>'+
        '<td style="text-align: right; vertical-align: middle; ">'+tatol.sbProfit+'</td>'+
        '<td style="text-align: right; vertical-align: middle; ">'+tatol.gpProfit+'</td>'+
        '<td style="text-align: right; vertical-align: middle; ">'+tatol.rebateProfit+'</td>'+
        '<td style="text-align: right; vertical-align: middle; ">'+tatol.hdzsProfit+'</td>'+
        '<td style="text-align: center; vertical-align: middle; width: 150px; "></td>'+
        '<td style="text-align: center; vertical-align: middle; width: 150px; "></td>'
    '</tr></tbody></table></div>';
	
    return rowTem;
}

$(function () {
    var defaultColunms = Revenue.initColumn();
    var table = new BSTable(Revenue.id, "/revenue/select", defaultColunms,Revenue);
    table.setPaginationType("server");
    table.setQueryParams(Revenue.formParams());
	table.height=770;
	table.setSize(15);
    Revenue.table = table.init();
	//添加表头
	$(".fixed-table-toolbar").after("<div style='text-align: center;vertical-align: middle;font-size: 22px;color: #6979d7;font-weight: bold;'> 盈亏报表</div>");
	$("#RevenueTable").after(Revenue.tatol());
});
